package com.webchat.user.controller;

import com.webchat.common.bean.APIPageResponseBean;
import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.domain.vo.request.AccountRelationQueryDTO;
import com.webchat.domain.vo.request.CreateAccountRequestVO;
import com.webchat.domain.vo.request.CreateRobotRequestVO;
import com.webchat.domain.vo.request.UserRegistryInfoRequestVO;
import com.webchat.domain.vo.request.ValidateAccountPasswordReqVO;
import com.webchat.domain.vo.response.UserBaseResponseInfoVO;
import com.webchat.domain.vo.response.UserBaseResponseVO;
import com.webchat.rmi.user.UserServiceClient;
import com.webchat.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @Author 程序员七七
 * @webSite https://www.coderutil.com
 * @Date 2025/1/14 00:54
 * @description
 */
@RestController
public class UserServiceController implements UserServiceClient {

    @Autowired
    private UserService userService;

    @Override
    public APIResponseBean<UserBaseResponseInfoVO> userInfo(String userId) {

        return APIResponseBeanUtil.success(userService.getUserInfoByUserId(userId));
    }

    @Override
    public APIResponseBean<Set<String>> getAllSubscriberByAccount(Integer relationType, String account) {

        return APIResponseBeanUtil.success(userService.getAllSubscriberByAccount(relationType, account));
    }

    @Override
    public APIResponseBean<Boolean> isSubscribe(Integer relationType, String userAccount, String account) {

        return APIResponseBeanUtil.success(userService.isSubscribe(relationType, userAccount, account));
    }

    @Override
    public APIResponseBean<Map<String, Boolean>> batchIsSubscribe(@RequestBody AccountRelationQueryDTO accountRelationQuery) {
        return APIResponseBeanUtil.success(userService.batchIsSubscribe(accountRelationQuery.getRelationType(),
                accountRelationQuery.getSourceAccountIds(), accountRelationQuery.getTargetAccountId()));
    }

    @Override
    public APIResponseBean<UserBaseResponseVO> userBaseInfo(String mobile) {

        return APIResponseBeanUtil.success(userService.getUserBaseByMobile(mobile));
    }

    @Override
    public APIResponseBean<UserBaseResponseVO> userNameBaseInfo(String name) {

        return APIResponseBeanUtil.success(userService.getUserBaseByName(name));
    }

    @Override
    public APIResponseBean<Boolean> registry(@RequestBody UserRegistryInfoRequestVO request) {
        boolean registerResult = userService.registry(request.getPhoto(), request.getUserName(), request.getMobile(), request.getPassword());
        return APIResponseBeanUtil.success(registerResult);
    }

    @Override
    public APIPageResponseBean<UserBaseResponseInfoVO> page(String userId, Integer roleCode, String userName, String mobile, Integer pageNo, Integer pageSize) {

        return userService.page(userId, roleCode, userName, mobile, pageNo, pageSize);
    }

    @Override
    public APIResponseBean createRobot(@RequestBody CreateRobotRequestVO requestPram) {
        userService.createRobot(requestPram);
        return APIResponseBeanUtil.success("创建成功");
    }

    @Override
    public APIResponseBean createPublicAccount(@RequestBody CreateAccountRequestVO requestPram) {
        userService.createPublicAccount(requestPram);
        return APIResponseBeanUtil.success("创建成功");
    }

    @Override
    public APIResponseBean createServerAccount(@RequestBody CreateAccountRequestVO requestPram) {
        userService.createServerAccount(requestPram);
        return APIResponseBeanUtil.success("创建成功");
    }

    @Override
    public APIResponseBean<Map<String, UserBaseResponseInfoVO>> batchGet(@RequestBody Set<String> userIds) {
        Map<String, UserBaseResponseInfoVO> map = userService.batchGet(userIds);
        return APIResponseBeanUtil.success(map);
    }

    @Override
    public APIResponseBean<List<UserBaseResponseInfoVO>> batchGet(@RequestBody List<String> userIds) {
        return APIResponseBeanUtil.success(userService.batchGetUserListInfoFromCache(userIds));
    }

    @Override
    public APIResponseBean<UserBaseResponseInfoVO> queryAccount(String account) {

        return APIResponseBeanUtil.success(userService.queryAccount(account));
    }

    @Override
    public APIResponseBean<Boolean> validateAccountPassword(@RequestBody ValidateAccountPasswordReqVO validateAccountPasswordReq) {
        boolean validateRes = userService.validateAccountPassword(validateAccountPasswordReq.getAccountId(),
                                                                  validateAccountPasswordReq.getPassword());
        return APIResponseBeanUtil.success(validateRes);
    }
}
